package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Sms_Home_Subject_Spu_Mapper;
import com.shop.pojo.sms.Sms_Home_Subject_Spu;
import com.shop.service.Sms_Home_Subject_Spu_Service;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 后台专题列表关联的专题商品-李贝贝
 */
@Service
public class Sms_Home_Subject_Spu_ServiceImpl implements Sms_Home_Subject_Spu_Service {

    @Autowired
    private Sms_Home_Subject_Spu_Mapper sms_home_subject_spu_mapper;

    /**
     * 后台显示所有专题列表关联的专题商品
     * @param page
     * @param sms_home_subject_spu
     * @return
     */
    @Override
    public LayuiUtils<Sms_Home_Subject_Spu> find_admin_sms_home_subject_spu(Page<Sms_Home_Subject_Spu> page, Sms_Home_Subject_Spu sms_home_subject_spu) {
        LayuiUtils<Sms_Home_Subject_Spu> layuiUtils = new LayuiUtils<>();
        QueryWrapper<Sms_Home_Subject_Spu> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("subject_id",sms_home_subject_spu.getSubject_id());//专题ID
        if (sms_home_subject_spu.getName() != null){//专题名字
            queryWrapper.like("name",sms_home_subject_spu.getName());
        }
        Page<Sms_Home_Subject_Spu> sms_home_subject_spuPage = sms_home_subject_spu_mapper.selectPage(page,queryWrapper);
        layuiUtils.setCount(sms_home_subject_spuPage.getTotal());
        layuiUtils.setData(sms_home_subject_spuPage.getRecords());
        return layuiUtils;
    }

    /**
     * 后台添加专题列表关联的专题商品
     * @param sms_home_subject_spu
     * @return
     */
    @Override
    public R insert_sms_home_subject_spu(Sms_Home_Subject_Spu sms_home_subject_spu) {
        int insert = sms_home_subject_spu_mapper.insert(sms_home_subject_spu);
        if (insert > 0){
            return R.success();
        }
        return R.error(500,"添加失败");
    }

    /**
     * 后台删除专题列表关联的专题商品
     * @param id
     * @return
     */
    @Override
    public R delete_sms_home_subject_spu(List<Long> id) {
        int i = sms_home_subject_spu_mapper.deleteBatchIds(id);
        if (i > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    /**
     * 后台修改专题列表关联的专题商品
     * @param sms_home_subject_spu
     * @return
     */
    @Override
    public R update_sms_home_subject_spu(Sms_Home_Subject_Spu sms_home_subject_spu) {
        int i = sms_home_subject_spu_mapper.updateById(sms_home_subject_spu);
        if (i > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }
}
